<template>
    <view class="container paddingBottomBar" :style="themeColor"> </view>
</template>

<script>
import { mapMutations } from "vuex"
import orderInfoItem from "@/pages_shop/components/order/order-info-item.vue"
import orderRelation from "@/pages_shop/components/order/order-relation.vue"
import cardGroupCell from "@/components/common/cell/card-group-cell.vue"
import { GetReturnAddress } from "@/service/api/member.js"

import { CancelRefundApplyOrder, GetRefundDetail } from "@/service/api/order.js"

export default {
    components: {
        orderInfoItem,
        cardGroupCell,
        orderRelation,
    },
    data() {
        return {
            config: {
                title: "退款单详情",
                color: ["#ffffff"],
                centerSlot: true,
                barPlaceholder: true,
            },
            id: 0,
            type: "请选择快递公司",
            odd: "",
            data: {},
            isLoading: false,
            expressId: null,
            express: [],
            expressList: [],
            address: {},
            Details: [],
            showImgs: [],
            showImgsExs: [],
            imgs: [],
            imgsExs: [],
            Message: "",
            showAddress: false,
        }
    },
    created() {
        this.config.backgroundColor = [1, this.getThemeColor]
    },
    onLoad(e) {
        this.id = e.id
    },
    mounted() {
        this.getDetail()
    },
    methods: {
        ...mapMutations(["UP_RETURN_ORDER_VIEW"]),
        getBtnText() {
            //获取订单状态对应按钮文字
            let btnText = ""
            switch (this.data.State) {
                case 0:
                    btnText = "退款审核中"
                    break
                case 1:
                    btnText = "待退款"
                    break
                case 2:
                    btnText = "已取消"
                    break
                case 3:
                    btnText = "退款中"
                    break
                case 8:
                    btnText = "已驳回"
                    break
                case 9:
                    btnText = "已退款"
                    break
                default:
                    btnText = "退款审核中"
                    break
            }
            return btnText
        },
        goGoodsList() {
            this.easyGoTo("/pages_shop/packet/return/returnGoodsList?id=" + this.data.ID)
        },
        //获取详情
        getDetail() {
            let param = {
                id: this.id,
            }
            let path = "?exchangeId=" + this.id
            this.isLoading = true
            GetRefundDetail(param, path).then((res) => {
                this.data = res.Data
                this.Details = res.Data.DetailList
                if (res.Data.Address) {
                    if (res.Data.Address.ExpressName) {
                        this.type = res.Data.Address.ExpressName
                        this.showAddress = true
                    } else {
                        this.type = "商家配送"
                        this.showAddress = false
                    }
                } else {
                    this.showAddress = false
                }

                if (res.Data.CheckMsg) {
                    this.Message = res.Data.CheckMsg
                }
                this.isLoading = false
                this.getImageList(res.Data.DetailList)
            })
        },
        getImageList(list) {
            let arr = []
            if (list) {
                list.forEach((e) => {
                    arr.push(e.ProductImage)
                })
            }
            if (list.length == 1) {
                this.itemname = list[0].ProductName
            }
            this.imgs = arr
            this.showImgs = arr.slice(0, 3)
        },
        //退单作废
        cancellation() {
            this.$refs.delTip.open()
        },
        _cancelOrder() {
            var that = this
            let param = {
                exchangeId: this.id,
            }
            let path = "?exchangeId=" + this.id
            CancelRefundApplyOrder(param, path).then((res) => {
                if (res.State == 1) {
                    uni.showToast({
                        title: "作废成功",
                        icon: "none",
                        duration: 2000,
                    })
                    setTimeout(() => {
                        that.getDetail()
                    }, 2000)
                    that.upOrderView()
                } else {
                    uni.showToast({
                        title: res.Msg,
                        icon: "none",
                        duration: 2000,
                    })
                }
            })
        },
        upOrderView() {
            this.UP_RETURN_ORDER_VIEW(new Date().getTime())
        },
        close() {
            this.$refs.delTip.close()
        },
        doDel() {
            this.close()
            this._cancelOrder()
        },
    },
}
</script>

<style lang="scss" scoped>
.container {
    display: flex;
    flex-direction: column;
}

.rel {
    position: relative;

    .docleft {
        left: -20rpx;
        top: -40rpx;
        bottom: auto;
    }

    .docright {
        right: -20rpx;
        top: -40rpx;
        bottom: auto;
    }
}

.pure-top {
    width: 100%;
    height: 206rpx;
    position: relative;
    z-index: 0;
    overflow: hidden;

    &:after {
        content: "";
        width: 120%;
        height: 206rpx;
        position: absolute;
        left: -10%; //椭圆左边隐藏10%，右边隐藏10%
        top: 0;
        border-radius: 0 0 50% 50%; //左上角，右上角，右下角，左下角
        background: $app-color-main;
    }
}

.infomain {
    margin: 0 24rpx;
    margin-top: -206rpx;
    position: relative;
    z-index: 10;
}

.bottom-btn {
    padding: 0 24rpx;

    .btn {
        height: 84rpx;
        border-radius: 44rpx;
        border: 2rpx solid $app-color-main;
        margin-top: 48rpx;
        font-size: 32rpx;
        color: $app-color-main;
    }
}

.detail-header {
    height: 108rpx;
    display: flex;
    align-items: center;
    justify-content: center;

    image {
        margin-right: 10rpx;
    }

    text {
        font-weight: 500;
        font-size: $font-size-36;
        color: $color-white;
    }
}

.detail {
    background: #ffffff;
    border-radius: 16rpx;

    .docleft {
        position: absolute;
        left: -20rpx;
        bottom: -20rpx;
        width: 40rpx;
        height: 40rpx;
        border-radius: 50%;
        background: $uni-bg-color-grey;
        z-index: 2;
    }

    .docright {
        position: absolute;
        right: -20rpx;
        bottom: -20rpx;
        width: 40rpx;
        height: 40rpx;
        border-radius: 50%;
        background: $uni-bg-color-grey;
        z-index: 2;
    }
    .refund_top {
        padding: 0 24rpx;
        position: relative;
        border-bottom: 1rpx dotted #ebebeb;

        .refund_top_price {
            display: flex;
            font-size: 36rpx;
            color: $app-color-main;
            font-weight: bold;
            padding: 54rpx 0rpx 32rpx 0rpx;
        }

        .refund_top_b {
            font-size: 28rpx;
            color: #666;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-bottom: 44rpx;
        }
        .refund_top_b {
            font-size: 28rpx;
            color: #666;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-bottom: 44rpx;
        }
    }
    .detail-info {
        margin-top: 18rpx;
        padding-bottom: 32rpx;
        border-bottom: 1rpx dotted #ebebeb;
        position: relative;
    }
    .detail-item {
        margin-bottom: 20rpx;
    }

    .detail-info {
        margin-top: 18rpx;
        padding-bottom: 32rpx;
        border-bottom: 1rpx dotted #ebebeb;
        position: relative;
    }

    .detail-item {
        margin-bottom: 20rpx;
    }

    .item-itle {
        padding: $app-page-padding;
        display: flex;
        flex-direction: row;
        margin-bottom: 10rpx;
        align-items: center;

        .label-text {
            font-weight: 700;
            display: flex;
            flex: 1;
            color: $color-gray-1;
            font-size: $font-size-28;
        }

        .value-text {
            font-weight: 100;
            font-size: $font-size-28;
            color: $app-color-text-main;
            color: #000000;
        }
    }

    .price {
        .label-text {
            color: $color-red;
        }

        .value-text {
            font-weight: 700;
            color: $color-red;
        }
    }

    .detail-reason {
        display: flex;
        flex-direction: column;

        .reason-content {
            margin: $app-page-padding;
            padding: $app-page-padding $app-page-padding 34rpx $app-page-padding;
            background-color: $color-gray-5;

            text {
                font-size: $font-size-24;
            }
        }

        .reason-img {
            width: 120rpx;
            height: 120rpx;
            margin-right: 24rpx;
            border-radius: 4rpx;
        }

        .reason-img-box {
            margin-top: 24rpx;
            display: flex;
            flex-direction: row;
        }
    }
}
.pay-way-scroll {
    max-height: 50vh;
}

.order-info-item .label {
    font-size: $font-size-28;
}
.pop-address {
    .pay-way-scroll {
        height: 340rpx;
        border-bottom: solid 20rpx $border;
    }

    .pay-way {
        border-bottom: 0;
    }
}

.topimg {
    width: 48rpx;
    height: 48rpx;
}
.order-item-main {
    position: relative;
    display: flex;
    flex: 1;
    flex-direction: row;
    padding: 0 24rpx 48rpx 24rpx;
    border-bottom: 1rpx dotted #ebebeb;
}
.order-item-imgs {
    display: flex;
    flex: 1;
    flex-direction: row;
    align-items: center;
    .img-item {
        position: relative;
        margin-right: 24rpx;
        display: flex;
        align-items: center;
        .order-item-name {
            flex: 1;
            font-size: 28rpx;
            color: $color-gray-1;
            display: flex;
            align-items: center;
            padding-left: 14rpx;
        }
        .order-item-img {
            display: flex;
            width: 120rpx;
            height: 120rpx;
            // border: 1px solid $app-color-main;
            border-radius: 8rpx;
        }
        .text-num {
            display: flex;
            justify-content: center;
            align-items: center;
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 40rpx;
            border-bottom-left-radius: 10rpx;
            border-bottom-right-radius: 10rpx;
            color: $color-white;
            background: rgba($color-black, 0.3);
            font-size: $font-size-24;
        }
    }
}
.right-box {
    display: flex;
    flex-direction: row;
    align-items: center;
    .num-box {
        display: flex;
        flex-direction: column;
        margin-right: 16rpx;
        text {
            margin-bottom: 4rpx;
            &:last-child {
                margin-bottom: 0;
            }
        }
    }
}
.card-group-tui .card-group-cell {
    border: none;
    padding: 12rpx $app-page-padding 12rpx 0;
}
</style>
